package cn.codenest.consumer;

import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @author ：Hyman
 * @date ：Created in 2021/7/14 10:48
 * @description：
 * @modified By：
 * @version: $
 */
public class OtherConsumer implements Consumer {

    Channel channel = null;

    public OtherConsumer(Channel channel) {
        this.channel = channel;
    }

    @Override
    public void handleConsumeOk(String consumerTag) {
        System.out.println(consumerTag);
    }

    @Override
    public void handleCancelOk(String consumerTag) {
        System.out.println(consumerTag);
    }

    @Override
    public void handleCancel(String consumerTag) throws IOException {
        System.out.println(consumerTag);
    }

    @Override
    public void handleShutdownSignal(String consumerTag, ShutdownSignalException e) {
        System.out.println(consumerTag);
    }

    @Override
    public void handleRecoverOk(String consumerTag) {
        System.out.println(consumerTag);
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties basicProperties, byte[] bytes) throws IOException {
        String str = new String(bytes);
        Long deliveryTag = envelope.getDeliveryTag();
        System.out.println("OtherConsumer —— 接受到的字符串是：" + str + ",deliveryTag是:" + deliveryTag);
        channel.basicAck(deliveryTag, true);
        //channel.basicReject(deliveryTag, true);
    }
}
